#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct student {
	int age;
	char name[10];
};
typedef struct student STU;
int cmp_int(const void* p1, const void* p2) {
	return *(int*)p1 - *(int*)p2;
}
int cmp_char(const void* p1, const void* p2) {
	return strcmp((char*)p1, (char*)p2);
}
int cmp_STU_age(const void*p1,const void*p2){
	return (int)((STU*)p1)->age - (int)((STU*)p2)->age;
}
int cmp_STU_name(const void* p1, const void* p2) {
	return strcmp((char*)((STU*)p1)->name,(char*)((STU*)p2)->name);
}
int main()
{
	int arr1[10] = { 12,5,6,8,3,2,0,14,5,10 };
	int sz1 = sizeof(arr1) / sizeof(arr1[0]);
	qsort(arr1, sz1, sizeof(arr1[0]), cmp_int);
	for (int i = 0; i < sz1; i++) {
		printf("%d ", arr1[i]);
	}
	printf("\n");
	getchar();
	char arr2[10] = {'a','f','d','k','t','b','c','j','d','\0'};
	//gets(arr2);
	size_t sz2 = strlen(arr2);
	qsort(arr2, sz2, sizeof(arr2[0]), cmp_char);
	for (int i = 0; i < sz2; i++) {
		printf("%c ", arr2[i]);
	}
	printf("\n");
	STU arr3[3] = { {10,"zhangsan"},{12,"lishi"},{7,"jibo"}};
	int sz3 = sizeof(arr3) / sizeof(arr3[0]);
	qsort(arr3, sz3, sizeof(arr3[0]), cmp_STU_age);
	for (int i = 0; i < sz3; i++) {
		printf("%d,%s ", arr3[i].age, arr3[i].name);
	}
	printf("\n");
	qsort(arr3, sz3, sizeof(arr3[0]), cmp_STU_name);
	for (int i = 0; i < sz3; i++) {
		printf("%d,%s ", arr3[i].age, arr3[i].name);
	}
	return 0;
}